﻿/**
 * Created by Administrator on 2017/3/1 0001.
 */
var Preload=
{
    create:function()
    {
        var page={};

        var loader=new PIXI.loaders.Loader();
        var graphic_bg,graphic_loadingBottom,graphic_loading;
        var text_progress;
        var sp_logo;

        var arr_assets=[];
        arr_assets.push(
            'assets/images/1.png',
            'assets/images/2.png',
            'assets/images/创邑_LOGO.png',
            // 'assets/images/leaf.png',
            'assets/images/map.png',
            'assets/images/pageInfo_bg.png',
            'assets/images/pageInfo_line.png',
            'assets/images/pageInfo_start.png',
            'assets/images/pageInfo_t0.png',
            'assets/images/pageInfo_t1.png',
            'assets/images/pageInfo_t2.png',
            'assets/images/pageInfo_t3.png',
            'assets/images/pageInfo_t4.png',
            'assets/images/g0_bg.png',
            'assets/images/g1_bg.png',
            'assets/images/g2_bg.png',
            'assets/images/g0_bt0.png',
            'assets/images/g0_bt1.png',
            'assets/images/bt_close.png',
            'assets/images/heartPlane.png',
            'assets/images/heartRed.png',
            'assets/images/right0.png',
            'assets/images/right1.png',
            'assets/images/right2.png',
            'assets/images/right3.png',
            'assets/images/right4.png',
            'assets/images/g1_bt0.png',
            'assets/images/page0_bg.png',
            'assets/images/page0_cover.png',
            'assets/images/page0_t0.png',
            'assets/images/page0_t1.png',
            'assets/images/page0_t2.png',
            // 'assets/images/page1_at0.png',
            // 'assets/images/page1_at1.png',
            'assets/images/page1_bga.png',
            'assets/images/page1_bgb.png',
            'assets/images/page2_click.png',
            'assets/images/page2_frame.png',
            'assets/images/page2_i0.png',
            'assets/images/page2_i1.png',
            'assets/images/page2_i2.png',
            'assets/images/page2_i3.png',
            'assets/images/page2_i4.png',
            'assets/images/page2_t0.png',
            'assets/images/page2_t1.png',
            'assets/images/page2_t2.png',
            'assets/images/page2_t3.png',
            'assets/images/page2_t4.png',
            'assets/images/page2_t5.png',
            'assets/images/page3_mask.png',
            'assets/images/page3_t0.png',
            'assets/images/page3_t1.png',
            'assets/images/page3_t2.png',
            'assets/images/ver_t0.png',
            'assets/images/arrow.png',
            'assets/images/verHelp.png'
        );
        for(var i=0;i<10;i++)
        {
            arr_assets.push('assets/images/g0_'+i.toString()+'.png');
        }
        for(var i=0;i<12;i++)
        {
            arr_assets.push('assets/images/g1_'+i.toString()+'.png');
        }
        for(var i=0;i<14;i++)
        {
            arr_assets.push('assets/images/g2_'+i.toString()+'.png');
        }

        loader.add(arr_assets)
            .on("progress", loadProgressHandler)
            .load(completeHandler);
        function loadProgressHandler(loader, resource)
        {
            text_progress.text=Math.floor(loader.progress)+"%";
            graphic_loading.scale.x=loader.progress/100;
        }
        function completeHandler()
        {
            var event = new CustomEvent("Main_LoadComplete", {detail:loader });
            document.dispatchEvent(event);

            new TWEEN.Tween({alpha:1}).to({alpha:0},1000)
                .onUpdate(function()
                {
                    graphic_bg.alpha=this.alpha
                })
                .easing(TWEEN.Easing.Cubic.In)
                .start();

            new TWEEN.Tween({y:sp_logo.y,alpha:1}).to({y:sp_logo.y-100,alpha:0},700)
                .onUpdate(function()
                {
                    sp_logo.y=this.y;
                    sp_logo.alpha=this.alpha;
                })
                .easing(TWEEN.Easing.Cubic.InOut)
                .start();

            new TWEEN.Tween({y:graphic_loading.y,alpha:1}).to({y:graphic_loading.y+100,alpha:0},700)
                .onUpdate(function()
                {
                    graphic_loading.y=this.y;
                    graphic_loading.alpha=this.alpha;
                })
                .easing(TWEEN.Easing.Cubic.InOut)
             .start();

            new TWEEN.Tween({y:graphic_loadingBottom.y,alpha:1}).to({y:graphic_loadingBottom.y+100,alpha:0},700)
                .onUpdate(function()
                {
                    graphic_loadingBottom.y=this.y;
                    graphic_loadingBottom.alpha=this.alpha;
                })
                .easing(TWEEN.Easing.Cubic.InOut)
                .start();

            new TWEEN.Tween({y:text_progress.y,alpha:1}).to({y:text_progress.y+100,alpha:0},700)
                .onUpdate(function()
                {
                    text_progress.y=this.y;
                    text_progress.alpha=this.alpha;
                })
                .easing(TWEEN.Easing.Cubic.InOut)
                .start();
        }
        page.init=function(stage,stageW,stageH)
        {
            graphic_bg = new PIXI.Graphics();
            graphic_bg.beginFill(0x0);
            graphic_bg.drawRect(0,0,stageW,stageH);
            stage.addChild(graphic_bg);

            graphic_loadingBottom=new PIXI.Graphics();
            graphic_loadingBottom.beginFill(0xcccccc);
            graphic_loadingBottom.drawRect(0,0,300,2);
            graphic_loadingBottom.x=(stageW-graphic_loadingBottom.width)/2;
            graphic_loadingBottom.y=(stageH/2)+40;
            stage.addChild(graphic_loadingBottom);

            graphic_loading=new PIXI.Graphics();
            graphic_loading.beginFill(0xff6600);
            graphic_loading.drawRect(0,0,300,2);
            graphic_loading.x=(stageW-graphic_loading.width)/2;
            graphic_loading.y=(stageH/2)+40;
            graphic_loading.scale.x=0;
            stage.addChild(graphic_loading);

            sp_logo=new PIXI.Sprite.fromImage('assets/images/创邑_LOGO.png');
            sp_logo.anchor.set(0.5);
            sp_logo.x=stageW/2;
            sp_logo.y=stageH/2-50;
            stage.addChild(sp_logo);

            text_progress= new PIXI.Text('0%',{fontFamily : 'Arial', fontSize: 20, fill : 0xcccccc, align : 'center'});
            text_progress.anchor.x=0.5;
            text_progress.anchor.y=0.5;
            text_progress.x = stageW/2;
            text_progress.y = stageH/2+80;
            stage.addChild(text_progress);
        }

        return page;
    }
}
